package com.exit490.cfp.activities.transacao;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.Tab;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.exit490.cfp.R;
import com.exit490.cfp.activities.transacao.tab.DespesaTab;
import com.exit490.cfp.activities.transacao.tab.ReceitaTab;
import com.exit490.cfp.activities.transacao.tab.TransacoesTab;
import com.exit490.cfp.fragments.TabListener;

public class TransacaoActivity extends ActionBarActivity {

    private ActionBar actionBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transacao);
        montaTabBar();
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.transacao, menu);
        return super.onCreateOptionsMenu(menu);
    }

    public void cliqueBotaoAdicionarTransacao(MenuItem itemMenu) {
        Intent novaTransacao = new Intent(TransacaoActivity.this, NovaTransacaoActivity.class);
        startActivity(novaTransacao);
    }

    public void montaTabBar() {
        actionBar = getSupportActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setDisplayShowTitleEnabled(false);

        Tab tab = actionBar.newTab().setText("Receitas").setTabListener(new TabListener<ReceitaTab>(this, "receita", ReceitaTab.class));
        actionBar.addTab(tab);

        tab = actionBar.newTab().setText("Despesas").setTabListener(new TabListener<DespesaTab>(this, "despesa", DespesaTab.class));
        actionBar.addTab(tab);

        tab = actionBar.newTab().setText("Transações")
                .setTabListener(new TabListener<TransacoesTab>(this, "transacoes", TransacoesTab.class));
        actionBar.addTab(tab);

    }

}
